let MIXIN = {
	data() {
		return {
			sharePubtitle: '多米街',
			sharepath: '',
			shareimageUrl: '',
			sharequery: ''
		}
	},
	onLoad(options) {
		let mid = '';
		if (options.mid) {
			mid = options.mid;
		}
		if (options.scene) {
			let scene = decodeURIComponent(options.scene);
			mid = this.gup('mid', scene);
		}
		if(mid!=''){
			uni.setStorageSync('mid', mid);
		}
		this.getSharePath();
	},
	methods: {
		getSharePath(val = '',auto=false){
			let routes = getCurrentPages(); // 获取当前打开过的页面路由数组
			// 需要获取转发URL的页面路由
			let pathArr = [
				{
					type: 'home',
					child:['/pages/mallHome/index','/pages/index/index']
				},
				{
					type: 'goods',
					child:['/pages/product/product','/pages/product/groupbuy']
				},
				{
					type: 'goodsList',
					child:['/pages/product/list']
				},
				{
					type: 'merch',
					child:['/pages/shoplist/shopgoods']
				},
				{
					type: 'goodsvod',
					child:['/pages/product/videoDetail']
				},
				{
					type: 'other',
					child:['/pages/mallHome/selfMall','/pages/category/category','/pages/goodlist/goodlist','/pages/business/accounts','/pages/user/vipShop','/pages/shoptab/shoplist','/pages/user/vip','/pages/goodlist/specialPerformance','/pages/notice/moduleCont','/pages/index/accountsPaytype','/pages/taobao/detail','/pages/live/index']
				},
				{
					type: 'redpacket',
					child:['/pages/user/hb']
				},
			];
			// 禁止转发的路由页面
			let banPath = [
				'/pages/agent/QRcode','/pages/business/collection','/pages/business/personalstores','/pages/business/gallery','/pages/business/merch','/pages/business/accountdis','/pages/business/notice','/pages/groupmenu/addlabel','/pages/groupmenu/shoppersonnel','/pages/business/shoplistw','/pages/business/shopsetw','/pages/business/equipment','/pages/business/changeStoreManager','/pages/userservice/goodsExamine','/pages/business/collectionrecord','/pages/business/orderwrite','/pages/business/reservation','/pages/user/hbrecord','/pages/user/hbdetail','/pages/business/developStores'
			];
			// 禁止传参数的路由页面
			let banParam = ['/pages/user/hb'];
			if (routes.length > 0 && routes[routes.length - 1].$page) {
				// 判断是手动还是自动获取url参数
				if(!auto){
					this.sharepath = routes[routes.length - 1].$page.fullPath; //获取当前页面路由
				}else{
					this.sharepath = val;
				}
				console.log(this.sharepath);
				// 禁用页面转发
				banPath.forEach(item=>{
					// if(item.search(this.sharepath.split('?')[0])!=-1){
					if(item == this.sharepath.split('?')[0]){
						// console.log(this.sharepath)
						uni.hideShareMenu();
						console.log('页面禁止分享')
						return;
					}
				})
				// #ifdef MP-ALIPAY
				console.log('支付宝全局禁止分享')
				uni.hideShareMenu();
				// #endif
				let type;
				let cid = routes[routes.length - 1].options.id ? routes[routes.length - 1].options.id : 0;
				pathArr.forEach((item)=>{
					item.child.forEach((items)=>{
						// if(this.sharepath.includes(items)){
						if(this.sharepath.split('?')[0] == items){
							type = item.type;
							// 去掉多余参数，在cid已经传过
							banParam.forEach(itemss=>{
								if(itemss == items){
									this.sharepath = this.sharepath.split('?')[0];
								}
							})
							this.$axios('WxInfo/getConfig', 'POST', 'shop', {
								url: this.sharepath,
								type,
								cid
							}).then(res => {
								if (res.data.code == 200) {
									if(res.data.data.shareinfo.title){
										this.sharePubtitle = res.data.data.shareinfo.title;
									}
									this.sharepath = res.data.data.shareinfo.url;
									this.sharequery = res.data.data.shareinfo.url.split('?')[1];
									this.shareimageUrl = res.data.data.shareinfo.imgurl;
								}
							})
						}
					})
				})
			}
		},
		gup(name, url) {
			if (url) url = url ? '?' + url : location.href;
			name = name.replace(/[\[]/, "\\\[").replace(/[\]]/, "\\\]");
			var regexS = "[\\?&]" + name + "=([^&#]*)";
			var regex = new RegExp(regexS);
			var results = regex.exec(url);
			return results == null ? null : results[1];
		}
	},
	// #ifdef MP-WEIXIN
	//转发分享
	 onShareAppMessage() {
		console.log(this.sharepath);
	 	return {
	 		title: this.sharePubtitle,
	 		path: this.sharepath,
			imageUrl: this.shareimageUrl
	 	}
	 },
	 onShareTimeline() {
	 	return {
	 		title: this.sharePubtitle,
	 		// path: this.path,
			query: this.sharequery,
			imageUrl: this.shareimageUrl
	 	}
	 }
	// #endif
};
export default MIXIN;